import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		token: "",
		userInfo:{},
		indexInfo: {},
	},
	mutations: {
		changIndex(state, data) {
			state.indexInfo = data
		},
		changeperson(state,type){
			Vue.prototype.$ComFunJS.ajax({
				url: "/api/v1.0/user/userinfo",
				method: 'get',
				success: function(res) {
					if (!res.data.error) {
						state.userInfo = res.data.result;
					}
				}
			})				
		},			
		login(state, provider) {
			let token = provider
			state.hasLogin = true;
			if (provider.indexOf("FTSPTK_") == -1) {
				token = "FTSPTK_" + provider
			}
			state.token = token;
			Vue.prototype.$ComFunJS.token = token;
			uni.setStorage({ //缓存用户登陆状态
				key: 'token',
				data: token
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.token = "";
			state.userInfo = {};
			uni.removeStorage({
				key: 'token'
			});
			Vue.prototype.$ComFunJS.token = "";
		}
	},
	actions: {

	}
})

export default store
